* ==============================================================================
* 	Measuring Knowledge of Parties' Legislative Seat Shares
* 	Lee, Haime & Stevenson 
* 	Replication Do File: Hazard Rate (Figure 2)
* ==============================================================================

set scheme sol /* ado file available at: https://dl.dropbox.com/u/3011470/scheme_sol.zip */

********************************************************************************
*****   Figure 2: UNITED KINGDOM   *********************************************
********************************************************************************

use "hazardUK.dta", clear

/** recode missing == 0 **/

set more off
	destring partiesactivedup-partiesactivealliancepartyofnort, replace
	egen recog=rowtotal(partiesactivedup-partiesactivealliancepartyofnort)

	destring lrplacementdup-lrplacementalliancepartyofnorthe, replace
	egen LRplace=rowtotal(lrplacementdup-lrplacementalliancepartyofnorthe)

	destring positiontaxconservativeparty-positiontaxukip, replace
	egen taxpos=rowtotal(positiontaxyourself-positiontaxukip)

	destring positioneuconservativeparty-positioneuukip, replace
	egen eupos=rowtotal(positioneuconservativeparty-positioneuukip)

	destring positionscotlandconservativepart-positionscotlandukindependencepa, replace
	egen scotpos=rowtotal (positionscotlandyourself-positionscotlandukindependencepa)

	destring influencedup-influencealliancepartyofnorthern, replace
	egen influ=rowtotal(influencedup-influencealliancepartyofnorthern)

	destring freqingovtdup-freqingovtalliancepartyofnorther, replace
	egen freqgov=rowtotal(freqingovtdup-freqingovtalliancepartyofnorther)

	destring  currentroledup-currentrolealliancepartyofnorthe, replace
	egen role=rowtotal(currentroledup-currentrolealliancepartyofnorthe)

	destring ministershiptreasury-ministershiphomeoffice, replace
	egen ministership=rowtotal(ministershiptreasury-ministershiphomeoffice)	
	egen temp1 = anymatch(currentroledup-currentrolealliancepartyofnorthe), values(1)
	egen temp2 = anymatch(currentroledup-currentrolealliancepartyofnorthe), values(2)
	replace ministership=999 if temp1==0&role!=0			// Rs not shown with this question
	replace ministership=999 if temp1==1&temp2==0&role!=0	// Rs not shown with this question
	drop temp1 temp2

	destring econeval, replace 
	recode econeval .=0

	destring attentionchecktheguardian-attentioncheckdailystar, replace
	egen attentionscore= rowtotal(attentionchecktheguardian-attentioncheckdailystar)
	recode attentionscore .=0

	destring earthquake, replace
	recode earthquake .=0

	destring eureferendumconservatives-eureferendumgreens, replace
	egen euref = rowtotal(eureferendumconservatives-eureferendumgreens)

	destring supportcarers, replace 
	recode supportcarers .=0

	destring  seatsrandom_dup-seatsrandom_alliance, replace
	egen seats1=rowtotal(seatsrandom_dup-seatsrandom_alliance)

	destring seatsfixed_dup-seatsfixed_alliance, replace
	egen seats2=rowtotal(seatsfixed_dup-seatsfixed_alliance)

	destring percentrandom_dup-percentrandom_alliance, replace
	egen seats3=rowtotal(percentrandom_dup-percentrandom_alliance)
	
	destring percentfixed_dup-percentfixed_alliance, replace
	egen seats4=rowtotal(percentfixed_dup-percentfixed_alliance)

	egen seats=rowtotal(seats1 seats2 seats3 seats4)


/** Recode all these variables: missing == 1 and non-missing == 0;
	keep them in the order in which they appeared in the survey **/

	set more off
	foreach var of varlist recog LRplace taxpos eupos scotpos influ freqgov role ministership econeval attentionscore earthquake euref supportcarers seats {
		recode `var' 0=1 *=0
	}

/** When a person has dropped out there will be a set of consecutive ones in the each of these variables;
	we started with 1665 individuals, 23 dropped out at the first question;
	get one line with the number who have dropped out at each question **/

	collapse (sum) recog LRplace taxpos eupos scotpos influ freqgov role  ministership econeval attentionscore earthquake euref supportcarers seats 

/** make the columns rows **/

	local aa=1
	foreach var of varlist recog LRplace taxpos eupos scotpos influ freqgov role ministership econeval attentionscore earthquake euref supportcarers seats {
		rename `var' var`aa'
		local aa=`aa'+1
	}

	gen index=1
	reshape long var, i(index) j(j)
	drop index
	list

/** we started with 1665 individuals; add a column to count how many people reached the question  */

	tsset j
	gen surviors= 1665-l.var
	replace surviors= 1665 in 1
	list

/* now we have the total number of people who have quit by each question and the number who reached the question;
   now we need the number who quit at each question (not the total who have quit by then) */

	gen fails=var-l.var
	list
	replace fail=23 in 1
	list

/* Get the hazard rate for each question */
   
	capture drop hazard
	gen hazard=fail/surviors
	list

/** [Figure 2] UK Graph **/

	gen varlab=""  
	local kk=1
	foreach vv in "Party recognition" "Party LR position" "Party tax position" ///
		"Party EU position" "Party scottish position"  "Party policy influence" ///
		"Party frequency in cabinet" "Party role in cabinet" "Party control of ministeries" ///
		"Evaluation of economy" "Media use: attention test" "Knowledge: earthquake" ///
		"Knowledge: EU referendum" "Knowledge: support carers" "Expected seats" { 
		replace varlab="`vv'" in `kk' 
		local kk=`kk'+1
	}
	set more off
	list

	graph bar hazard, over(varlab, sort(j)) ylabel(0(0.02)0.06) horizontal ///
		ytitle("Hazard Rate") title("United Kingdom") name(figure2_uk, replace)
	
	
********************************************************************************
*****   Figure 2: DENMARK   ****************************************************
********************************************************************************

use "hazardDK.dta", clear
set scheme sol

/** recode missing == 0 **/

set more off
	destring polint, replace 
	recode polint .=0

	destring polknowledge, replace
	recode polknowledge .=0

	destring  q7_1-q7_10, replace
	egen recog=rowtotal(q7_1-q7_10)

	destring  q9_1-q9_10, replace
	egen LRplace=rowtotal(q9_1-q9_10)

	destring  q11_1-q11_10, replace
	egen taxpos=rowtotal(q11_1-q11_10)

	destring  q13_1-q13_10, replace
	egen eupos=rowtotal(q13_1-q13_10)

	destring  q15_1-q15_10, replace
	egen aslpos=rowtotal(q15_1-q15_10)

	destring  q17_2-q17_1, replace
	egen influ=rowtotal(q17_2-q17_1)

	destring  q19_1-q19_10, replace
	egen freqgov=rowtotal(q19_1-q19_10)

	destring  q21_1-q21_10, replace
	egen role=rowtotal(q21_1-q21_10)

	rename q25 econeval
	destring econeval, replace 
	recode econeval .=0

	rename q29 newsscand
	destring newsscand, replace 
	recode newsscand .=0

	destring  q31_1-q31_6, replace
	egen newsuk=rowtotal(q31_1-q31_6)

	rename q33 newswork
	destring newswork, replace 
	recode newswork .=0

	foreach var of varlist q37-q46 {
	destring `var', replace 
	recode `var' .=0
	}

	rename q49 voteint
	destring voteint, replace 
	recode voteint .=0

	destring  q51_1_16-q51_10_16, replace
	egen seats1=rowtotal(q51_1_16-q51_10_16)

	destring q53_9_2-q53_10_2, replace
	egen seats2=rowtotal(q53_9_2-q53_10_2)

	destring  q55_1_1-q55_10_1, replace
	egen seats3=rowtotal(q55_1_1-q55_10_1)

	destring  q57_9_1-q57_10_1, replace
	egen seats4=rowtotal(q57_9_1-q57_10_1)

	egen seats=rowtotal(seats1 seats2 seats3 seats4)

	
/** Recode all these variables: missing == 1 and non-missing == 0;
	keep them in the order in which they appeared in the survey **/

	set more off
	foreach var of varlist polint polknowledge recog LRplace taxpos eupos aslpos influ freqgov role econeval newsscand newsuk newswork voteint seats {
		recode `var' 0=1 *=0
}

/** When a person has dropped out there will be a set of consecutive ones in the each of these variables;
	we started with 1917 individuals, 4 dropped out at the first question;
	get one line with the number who have dropped out at each question **/

	collapse (sum) polint polknowledge recog LRplace taxpos eupos aslpos influ freqgov role econeval newsscand newsuk newswork voteint seats

/** make the columns rows */

	local aa=1
	foreach var of varlist polint polknowledge recog LRplace taxpos eupos aslpos influ freqgov role econeval newsscand newsuk newswork voteint seats {
		rename `var' var`aa'
		local aa=`aa'+1
	}

	gen index=1
	reshape long var, i(index) j(j)
	drop index
	list

/** we started with 1917 individuals; add a column to count how many people reached the question  */
	
	tsset j
	gen surviors=1917-l.var
	replace surviors=1917 in 1
	list

/* now we have the total number of people who have quit by each question and the number who reached the question;
   now we need the number who quit at each question (not the total who have quit by then) */

	set more off
	gen fails=var-l.var
	list
	replace fail=4 in 1
	list

/** Get the hazard rate for each question **/
   
	set more off
	capture drop hazard
	gen hazard=fail/surviors
	list
 
/** [Figure 2] DK Graph **/

	gen varlab=""  
	local kk=1
	foreach vv in "Political interest" "Political knowledge" "Party recognition" ///
		"Party LR position" "Party tax posistion" "Party EU position" ///
		"Party asylum position" "Party policy influence" "Party frequency in cabinet" ///
		"Party role in cabinet" "Evaluation of economy" "News awareness: scandal" ///
		"News awareness: UK election" "News awareness: work hours" "Vote intention" ///
		"Expected seats" { 
		replace varlab="`vv'" in `kk' 
		local kk=`kk'+1
	}
	set more off
	list

	graph bar hazard, over(varlab, sort(j)) horizontal ytitle("Hazard Rate") ///
		title("Denmark") name(figure2_dk, replace)
		
/** [Figure 2] UK and DK combined **/

	graph combine figure2_uk figure2_dk, xsize(4) ysize(1.6) colfirst iscale(*1.5) imargin(zero) graphregion(margin(zero)) plotregion(margin(tiny))
	graph export "figure2.pdf", replace
	
	
	
*\END
